{% extends "PlatBundle::layout.html.twig" %}


{% block title %}超级管理员帐号管理{% endblock %}

{% block css %}{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}



    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">系统设置</span>
            </div>
            <div class="top-nav top-nav-active">超级管理员账号管理</div>
        </div>
        <div class="main-content">

            <div class="mes-content">
                <div class="main-mes-top">
                    <div class="fl">
                        <a class="release-btn fl" style="width:160px;" href="{{ path('plat_edit_admin_account',{id:'0'}) }}">
                            <div class="train-width" style="width: 125px;">
                                <span class="me-icon fl"></span>
                                <span class="re-text fl">添加超级管理员</span>
                            </div>
                        </a>
                    </div>

                    <div class="fr">
                        {#<div class="mes-input fl">#}
                            {#<input type="text" class="keyword-input" name="keyword" placeholder="请输入关键词">#}
                        {#</div>#}

                        <select name="company" class="mes-select fl">
                            <option value="">请选择所属区域</option>
                            {% for item in data.data %}
                                <option value="{{ item.id }}">{{ item.name }}</option>
                            {% endfor %}
                        </select>

                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released fl">超级管理员列表</div>

                    <table class="table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th style="width: 6%;" class="center-th">序号</th>
                            <th style="width: 12%;" class="center-th">所属区域</th>
                            <th style="width:12%;" class="center-th">超级管理员账号（手机号）</th>
                            <th class="center-th">管理员名称</th>
                            <th class="center-th">姓名</th>
                            <th class="center-th">邮箱</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>




                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">


                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}

{% block box %}{% endblock %}

{% block javascript %}
    {{ parent() }}
<script type="text/javascript">

        SidebarHighlighting('8');
        SonSidebar("8","3");

        var district_id = "";

        //重置密码
        $('body').on('click','.ta-reset', function() {
            var id = $(this).data("id");
            if(confirm('您确定要重置此密码吗？')) {
                $.getJSON("{{ path('api_platform_plat_reset_password') }}",{id:id},function(data){
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, data.message, 1,'', true);
                    } else {
                        popStatus(2, data.message, 1,'', true);
                    }

                })

            }
        });

        // 禁用
        $('body').on('click','.tab-disable', function() {
            var id = $(this).data("id");
            var status = $(this).data("status");

            if(status == "0"){
                var comfirm = "您确定要禁用帐号吗？";
            } else {
                var comfirm = "您确定要启用帐号吗？";
            }
            if(confirm(comfirm)) {
                $.post("{{ path('api_platform_change_admin_auth') }}",{id:id,status:status},function(data){
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, data.message, 1,'', true);
                        $("table tbody").empty();
                        page_times = 0;
                        getList(1);
                    } else {
                        popStatus(2, data.message, 1,'', true);
                    }
                })


            }
        });

        // 获取帐号列表
        var page_times = 0;
        function getList(page,district_id){
            page_times++;
            var param = {page:page};

            if($.trim(district_id) != ""){
                param.district_id = district_id;
            }

            $.getJSON("{{ path('api_platform_admin_account_list') }}",param,function(data){
                $("table tbody").empty();
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(allpage == 0){
                    $(".pagination").empty();
                }
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                var item = data.data.data;
                for(var i in item){
                    var html = '';
                    var key = parseInt(i)+1;

                    var list_order_num = parseInt((parseInt(page)-1)*10+key);

                    if(item[i].admin_role_id == 2){
                        var admin_role = "超级管理员";
                    }

                    var info_url = "{{ path('plat_edit_admin_account',{id:'74556859043'}) }}".replace("74556859043",item[i].id);

                    html += '<tr>';
                    html += '<td class="a-line center-th">'+ list_order_num +'</td>';
                    html += '<td class="center-th">'+ item[i].district_name +'</td>';
                    html += '<td class="center-th">'+ item[i].phone +'</td>';
                    html += '<td class="center-th">'+ item[i].nickname +'</td>';
                    html += '<td class="center-th">'+ item[i].realname +'</td>';
                    html += '<td class="center-th">'+ item[i].email +'</td>';
                    html += '<td class="center-th">';

                    if(item[i].status == 1){
                        html += '<span class="table-opera ta-reset" style="display: block;" data-id="'+ item[i].id +'">重置密码</span>';
                        html += '<a href="'+ info_url +'" class="table-opera tab-edit" data-id="'+ item[i].id +'">编辑 |</a>';
                        html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'" data-status="0">禁用</span>';
                    } else {
                        html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'" data-status="1">启用</span>';
                    }

                    html += '</td>';
                    html += '</tr>';


                    $("table tbody").append(html);
                }

            })
        }

        addSearchAction(1);  //4

        //5
        function addSearchAction(page){

            getList(page,district_id);
        }

        //查询
        $('.mes-query-btn').on('click', function() {

            district_id = $("select[name='company']").val();


            page_times = 0;
            addSearchAction(1);

        });
</script>
{% endblock %}